﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using REVISIONMAX30.Frame;

namespace REVISIONMAX30.Controls
{
    public partial class MyResultList : UserControl
    {
        public MyResultList()
        {
            InitializeComponent();
        }

        public UIHandler uiHandler { get; set; }

        public void AddResult(FrResultType pFrResult)
        {
            if (pFrResult.Message.HasValue())
            {
                AddItemToListView(pFrResult);

                foreach (var tSubResult in pFrResult.SubResultList)
                {
                    if (tSubResult.Message.HasValue())
                    {
                        AddResult(tSubResult);
                    }
                }
            }
        }

        public void AddItemToListView(FrResultType pFrResult)
        {
            var tlvItem = this.lvResults.Items.Add(pFrResult.Severity.ToString() );

            tlvItem.SubItems.Add(pFrResult.Message);

            if (pFrResult.Severity < FrResultSeverityType.Warning)
            {
                tlvItem.BackColor = Color.White;
            }
            else if (pFrResult.Severity == FrResultSeverityType.Warning)
            {
                tlvItem.BackColor = Color.LightYellow;
            }
            else if (pFrResult.Severity >= FrResultSeverityType.Error)
            {
                tlvItem.BackColor = Color.LightSalmon;
            }

        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            this.lvResults.Items.Clear();
        }
    }

}
 
